package com.dgut.controller;

import com.dgut.common.OnOrOff;
import com.dgut.pojo.IntellectualProperty;
import com.dgut.service.IntellectualPropertyService;
import com.dgut.utils.PageRequestInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Api(value = "IntellectualPropertyController")
@RestController
@CrossOrigin
@RequestMapping("/intellectualProperty")
public class IntellectualPropertyController {
    @Resource
    private IntellectualPropertyService intellectualPropertyService;

    /**
     * start-zwb
     */
    /**
     * end-zwb
     */


    /**
     * start-gxd
     */
    /**
     * end-gxd
     */


    /**
     * start-lzh
     */
    @ApiOperation(value = "模糊查询知识产权",notes = "")
    @GetMapping("/getIntellectualPropertyByName")
    public Object getIntellectualPropertyByName(@ApiParam(value = "模糊查询",required = false)
                                                @RequestParam(required = false) String name){
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        List<IntellectualProperty> list = intellectualPropertyService.getIntellectualPropertyByName(name);
        resultMap.put("IntellectualPropertyList",list);
        return resultMap;
    }

    @ApiOperation(value = "根据id进入某一项相关知识产权详情页",notes = "")
    @GetMapping("/getIntellectualPropertyDetail")
    public Object getIntellectualPropertyDetail(@ApiParam(value = "知识产权id",required = true)
                                                @RequestParam int id,
                                                HttpSession httpSession){
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        IntellectualProperty intellectualProperty = intellectualPropertyService.getIntellectualPropertyDetail(id);
        resultMap.put("IntellectualPropertyList",intellectualProperty);
        httpSession.setAttribute("IntellectualPropertyId",id); //传知识产权id
        return resultMap;
    }

    @ApiOperation(value = "采买方购买某一项知识产权",notes = "")
    @PostMapping("/BuyIntellectualProperty")
    public Object BuyIntellectualProperty(@ApiParam(value = "传采买方id和知识产权实体类",required = true)
                                          @RequestParam Integer id,   //前段传采买方id和知识产权实体类
                                          @RequestBody IntellectualProperty intellectualProperty){
        // Integer id =  StpUtil.getLoginId();
        return  intellectualPropertyService.BuyIntellectualProperty(id,intellectualProperty);
    }
    @ApiOperation(value = "分页显示知识产权",notes = "")
    @PostMapping("/getIntellectualPropertyByPage")
    public Object getIntellectualPropertyByPage(@ApiParam(value = "传分页的页码和一页的显示数量",required = true)
                                                @RequestParam Integer pageNum,
                                                @RequestParam Integer pagesize){
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        Object result = intellectualPropertyService.getIntellectualPropertyByPage(new PageRequestInfo(pageNum, pagesize));
        resultMap.put("result",result);
        return result;
    }


    //知识产权商品管理部分
    @ApiOperation(value = "管理员分页查看知识产权商品", notes = "")
    @PostMapping("/getIntellectualPropertyByPage02")
    public Object getIntellectualPropertyByPage02(@ApiParam(value = "传分页的页码和一页的显示数量",required = true)
                                                      @RequestParam Integer pageNum,
                                                  @RequestParam Integer pagesize){
        return intellectualPropertyService.getIntellectualPropertyByPage02(new PageRequestInfo(pageNum, pagesize));
    }

    @ApiOperation(value = "添加知识产权商品", notes = "")
    @PostMapping("/InsertIntellectualProperty")
    public Object InsertIntellectualProperty(@ApiParam(value = "传知识产权实体类",required = true)
                                                 @RequestBody IntellectualProperty intellectualProperty){
        return intellectualPropertyService.InsertIntellectualProperty(intellectualProperty);
    }

    @ApiOperation(value = "根据知识产权商品id上架商品", notes = "")
    @GetMapping("/StackIntellectualProperty")
    public Object StackIntellectualProperty(@ApiParam(value = "传知识产权商品的id",required = true)
                                            @RequestParam Integer id){
        return intellectualPropertyService.StackIntellectualProperty(id);
    }

    @ApiOperation(value = "根据知识产权商品id下架商品",notes = "")
    @GetMapping("/UndercarriageIntellectualProperty")
    public Object UndercarriageIntellectualProperty(@ApiParam(value = "传知识产权商品id",required = true)
                                                    @RequestParam Integer id){
        return intellectualPropertyService.UndercarriageIntellectualProperty(id);
    }

    @ApiOperation(value = "根据知识产权商品的id删除商品",notes = "")
    @GetMapping("/DeleteIntellectualProperty")
    public Object DeleteIntellectualProperty(@ApiParam(value = "传要删除的知识产权商品id",required = true)
                                             @RequestParam Integer id){
        return intellectualPropertyService.DeleteIntellectualProperty(id);
    }

    @ApiOperation(value = "编辑修改知识产权商品")
    @PostMapping("/UpdateIntellectualProperty")
    public Object UpdateIntellectualProperty(@ApiParam(value = "传知识产权商品的实体类",required = true)
                                             @RequestBody IntellectualProperty intellectualProperty){
        return intellectualPropertyService.UpdateIntellectualProperty(intellectualProperty);
    }

    @ApiOperation(value = "前台查看已上架的知识产权")
    @GetMapping("/SelectONIntellectualProperty")
    public Object SelectONIntellectualProperty(@ApiParam(value = "传分页的页码和一页的显示数量",required = true)
                                                   @RequestParam Integer pageNum,
                                               @RequestParam Integer pagesize){
        return intellectualPropertyService.SelectONIntellectualProperty(new PageRequestInfo(pageNum, pagesize));
    }
    /**
     * end-lzh
     */

    /**
     * start-hwf
     */
    /**
     * end-hwf
     */

    /**
     * start-hqq
     */
    @ApiOperation(value = "通过名称查看已上架知识产权")
    @GetMapping("/getIntellectualPropertyOnByName")
    public Object getIntellectualPropertyOnByName(@ApiParam(value = "分页信息",required = true) PageRequestInfo pageRequestInfo,
                                                  @ApiParam(value = "知识产权名称",required = true) @RequestParam String name){
        return intellectualPropertyService.getIntellectualPropertyOnByName(pageRequestInfo, name);
    }
    /**
     * end-hqq
     */
}
